
package com.scalar.chiptrack.utils;

import com.scalar.ScalarException;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.*;
import java.util.*;

public final class StringUtils {

    private static Random random = new Random();

    // Balaram, April 17, 2005
    public static String incrementNumberPart( String input )
    {
        if( ( input == null ) || ( input.trim().length() == 0 ) )
        {
            return input;
        }

        input = input.trim();
        char[] inputChars = input.toCharArray();

        int index = (inputChars.length-1);
        for( ; index >= 0; index-- )
        {
            if( Character.isDigit( inputChars[index] ) != true )
            {
                break;
            }
        }

        String nextNumber = input.substring( 0, index + 1) + ( Integer.parseInt( input.substring( index +1 ) ) + 1 );

        return nextNumber;
    }


    public static String concatStrings (String[] strArr, String delim) {
        if ((strArr == null) || (delim == null)) {
            return null;
        }

        if (strArr.length == 0) {
            return "";
        }

        if (delim == null) {
            delim = ";";
        }

        StringBuffer buf = new StringBuffer();
        for (int i=0; i<strArr.length; i++) {
            if ((strArr[i] != null) && (strArr[i].trim().length() != 0)) {
                buf.append (strArr[i]).append (delim);
            }
        }

        return buf.toString();
    }

    public static String concatBytes (byte[] byteArr, String delim) {
        if ((byteArr == null) || (delim == null)) {
            return null;
        }

        if (byteArr.length == 0) {
            return "";
        }

        if (delim == null) {
            delim = ";";
        }

        StringBuffer buf = new StringBuffer();
        for (int i=0; i<byteArr.length; i++) {
            buf.append (byteArr[i] + delim);
        }

        return buf.toString();
    }

    public static String[] toStringArray (String val, String delim) throws ScalarException {
        if ((val == null) || (delim == null)) {
            return null;
        }

        String[] strArray = null;

        try {
            StringTokenizer st = new StringTokenizer (val, delim);
            strArray = new String [st.countTokens()];

            int i = 0;
            while (st.hasMoreTokens() == true) {
                strArray[i++] = st.nextToken();
            }
        }
        catch (NumberFormatException nfe) {
            throw new ScalarException ("Exception while convering to String array", nfe);
        }

        return strArray;
    }


    public static byte[] toByteArray (String val, String delim) throws ScalarException {
        if ((val == null) || (delim == null)) {
            return null;
        }

        byte[] byteArray = null;

        try {
            StringTokenizer st = new StringTokenizer (val, delim);
            byteArray = new byte [st.countTokens()];

            int i = 0;
            while (st.hasMoreTokens() == true) {
                byteArray[i++] = Byte.parseByte (st.nextToken());
            }
        }
        catch (NumberFormatException nfe) {
            throw new ScalarException ("Exception while convering to Byte array", nfe);
        }

        return byteArray;
    }

    public static Iterator parseString (String str, char delim) {
        char[] chars = str.toCharArray();

        ArrayList tokenList = new ArrayList();
        StringBuffer buf = new StringBuffer();

        for (int i=0; i<chars.length; i++) {
            if (chars[i] != delim) {
                buf.append (chars[i]);
            }
            else {
                tokenList.add (buf.toString().trim());
                buf.delete (0, buf.length());
            }
        }

        // Add last string token
        tokenList.add (buf.toString().trim());

        return tokenList.iterator();
    }

    //Added By SureshReddy on [17 JUNE 2004] for Converting DateFormat
    public static String formatDate(String inputDate)  {

        if (inputDate == null) {
            return null;
        }
        SimpleDateFormat sdfInput =  new SimpleDateFormat( "MM/dd/yyyy" );
        SimpleDateFormat sdfOutput =  new SimpleDateFormat ( "yyyy/MM/dd" );
        Date date =  new Date();
        try{
            date = sdfInput.parse( inputDate );
        }catch(ParseException e){

        }

        return  sdfOutput.format( date );
    }

     //Added by ChandraSekhar on 28 Dec 2004 for converting the Sql timestamp to mm/dd/yyy HH:mm:ss format
     public static String formatDateandTime( String inputDate )
     {

        if (inputDate == null)
        {
            return null;
        }
        SimpleDateFormat sdfInput =  new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
        SimpleDateFormat sdfOutput =  new SimpleDateFormat ( "MM/dd/yyyy HH:mm:ss" );
        Date date =  new Date();
        try
        {
            date = sdfInput.parse( inputDate );
        }
        catch( ParseException e )
        {

        }

        return  sdfOutput.format( date );
    }

	public static String formatDate(String inputDate, String inPutFormat, String outPutFormat )
	{
		if ( inputDate == null )
		{
			return null;
		}

		if( inPutFormat == null )
		{
			inPutFormat = "yyyy/MM/dd";
		}

		SimpleDateFormat sdfInput =  new SimpleDateFormat ( inPutFormat );

		if( outPutFormat == null )
		{
			outPutFormat = "MM/dd/yyyy";
		}

		SimpleDateFormat sdfOutput =  new SimpleDateFormat( outPutFormat );

		Date date =  new Date();
		try{
			date = sdfInput.parse( inputDate );
		}catch(ParseException e){

		}

		return  sdfOutput.format( date );
	}

    private static final String DEFAULT_DATE_FORMAT = "MM/dd/yyyy";

    public static Date format(String date)
    {
        return format(date, DEFAULT_DATE_FORMAT);
    }

    public static Date format(String date, String dateFormat)
    {
        if (date == null) {
            return null;
        }

        date = date.trim();

        if(isNullOrEmpty(dateFormat))

            dateFormat=DEFAULT_DATE_FORMAT;

        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
        ParsePosition position = new ParsePosition(0);
        return formatter.parse(date, position);
    }

    public static String formatDateToString (Date date) {
        return formatDateToString (date, DEFAULT_DATE_FORMAT);
    }

    public static String formatDateToString(Date date, String dateFormat)
    {
        if(date == null)
            return null;


        if(isNullOrEmpty(dateFormat))
            dateFormat=DEFAULT_DATE_FORMAT;

        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);

        return formatter.format(date);
    }

    public static java.sql.Date getSQLDate(String date, String dateFormat)
    {

        return (getSQLDate(format(date,dateFormat)));
    }

    public static java.sql.Date getSQLDate(java.util.Date date)
    {
        if(date==null)
            return null;

        return new java.sql.Date(date.getTime());
    }

    public static java.sql.Date getSQLDate(String date)
    {
        return (getSQLDate(format(date,null)));
    }

    // Balaram, July 4, 2003
    public static String formatAmount (float value )
    {
        return formatAmount( value, null );
    }

	// Added by Sharath on 18th April
	public static String formatAmount ( double value )
    {
        return formatAmount( value, null );
    }

    public static String formatAmount(float value, String pattern)
    {
        if( isNullOrEmpty( pattern ) )
        {
            pattern = "###,###,###,###.###";
        }
        DecimalFormat myFormatter = new DecimalFormat(pattern);

        String formattedAmount = myFormatter.format(value);

        int noOfDecimals=ConfigManager.getnoOfDecmalsInAmount();
        int index = formattedAmount.indexOf('.');
         if ( noOfDecimals == 3)
        {
            if (index == -1)
            {
                formattedAmount += ".000";
            }
            else
            {
                String substring = formattedAmount.substring (index+1, formattedAmount.length());
                if (substring.length() == 1)
                {
                    formattedAmount += "00";
                }
                if (substring.length() == 2)
                {
                    formattedAmount += "0";
                }
            }
        }
        else if ( noOfDecimals == 4)
        {
            if (index == -1)
            {
                formattedAmount += ".0000";
            }
            else
            {
                String substring = formattedAmount.substring (index+1, formattedAmount.length());
                if (substring.length() == 1)
                {
                    formattedAmount += "000";
                }
                if (substring.length() == 2)
                {
                    formattedAmount += "00";
                }
                if (substring.length() == 3)
                {
                    formattedAmount += "0";
                }
            }
        }
        return formattedAmount;
   }


    public static String formatAmount(double value, String pattern)
    {
        if( isNullOrEmpty( pattern ) )
        {
            pattern = "###,###,###,###.###";
        }
        DecimalFormat myFormatter = new DecimalFormat(pattern);

        String formattedAmount = myFormatter.format(value);
        
        int noOfDecimals=ConfigManager.getnoOfDecmalsInAmount();
        int index = formattedAmount.indexOf('.');

        if ( noOfDecimals == 3)
        {
            if (index == -1)
            {
                formattedAmount += ".000";
            }
            else
            {
                String substring = formattedAmount.substring (index+1, formattedAmount.length());
                if (substring.length() == 1)
                {
                    formattedAmount += "00";
                }
                if (substring.length() == 2)
                {
                    formattedAmount += "0";
                }
            }
        }
        else if ( noOfDecimals == 4)
        {
            if (index == -1)
            {
                formattedAmount += ".0000";
            }
            else
            {
                String substring = formattedAmount.substring (index+1, formattedAmount.length());
                if (substring.length() == 1)
                {
                    formattedAmount += "000";
                }
                if (substring.length() == 2)
                {
                    formattedAmount += "00";
                }
                if (substring.length() == 3)
                {
                    formattedAmount += "0";
                }
            }
        }
        return formattedAmount;
   }
   public static String formatAmountWithNoOfDecimals(float value)
    {
        //int noOfDecimals=0;
        String pattern = null;
        String formattedAmount = null;
        //noOfDecimals=ConfigManager.getnoOfDecmalsInAmount();
        String decimalPattern = ConfigManager.getDecmalsInAmountPattern();
        pattern = "$###,###,###,##0" + decimalPattern;
        DecimalFormat myFormatter = new DecimalFormat(pattern);
        formattedAmount = myFormatter.format(value);
        /*if( noOfDecimals == 2 )
        {
            pattern = "$###,###,###,###.##";
            DecimalFormat myFormatter = new DecimalFormat(pattern);

            formattedAmount = myFormatter.format(value);

            int index = formattedAmount.indexOf('.');
            if (index == -1)
            {
                formattedAmount += ".00";
            }
            else
            {
                String substring = formattedAmount.substring (index+1, formattedAmount.length());
                if (substring.length() == 1)
                {
                    formattedAmount += "00";
                }
                if (substring.length() == 2)
                {
                    formattedAmount += "0";
                }
            }
        }
        else if( noOfDecimals ==3 )
        {
            pattern = "$###,###,###,###.###";
            if( isNullOrEmpty( pattern ) )
            {
                pattern = "$###,###,###,###.###";
            }
            DecimalFormat myFormatter = new DecimalFormat(pattern);

            formattedAmount = myFormatter.format(value);

            int index = formattedAmount.indexOf('.');
            if (index == -1)
            {
                formattedAmount += ".000";
            }
            else
            {
                String substring = formattedAmount.substring (index+1, formattedAmount.length());
                if (substring.length() == 1)
                {
                    formattedAmount += "00";
                }
                if (substring.length() == 2)
                {
                    formattedAmount += "0";
                }
            }
        }*/
      return formattedAmount;
   }
   public static String formatAmountWithNoOfDecimals(double value)
    {
        //int noOfDecimals=0;
        String pattern = null;
        String formattedAmount = null;
        //noOfDecimals=ConfigManager.getnoOfDecmalsInAmount();
        String decimalPattern = ConfigManager.getDecmalsInAmountPattern();
        pattern = "$###,###,###,##0" + decimalPattern;
        DecimalFormat myFormatter = new DecimalFormat(pattern);
        formattedAmount = myFormatter.format(value);

        /*if( noOfDecimals ==2 )
        {
            pattern = "$###,###,###,###.##";
            DecimalFormat myFormatter = new DecimalFormat(pattern);

            formattedAmount = myFormatter.format(value);

            int index = formattedAmount.indexOf('.');
            if (index == -1)
            {
                formattedAmount += ".00";
            }
            else
            {
                String substring = formattedAmount.substring (index+1, formattedAmount.length());
                if (substring.length() == 1)
                {
                    formattedAmount += "00";
                }
                if (substring.length() == 2)
                {
                    formattedAmount += "0";
                }
            }
        }
        else if( noOfDecimals == 3 )
        {
            pattern = "$###,###,###,###.###";
            DecimalFormat myFormatter = new DecimalFormat(pattern);

            formattedAmount = myFormatter.format(value);

            int index = formattedAmount.indexOf('.');
            if (index == -1)
            {
                formattedAmount += ".000";
            }
            else
            {
                String substring = formattedAmount.substring (index+1, formattedAmount.length());
                if (substring.length() == 1)
                {
                    formattedAmount += "00";
                }
                if (substring.length() == 2)
                {
                    formattedAmount += "0";
                }
            }
        }*/
        return formattedAmount;
   }
   public static String formatUnits(int value)
   {
        DecimalFormat myFormatter = new DecimalFormat("###,###");
        return myFormatter.format(value);
   }

   /**
    * @return null if passed string value is not an integer
    */
    public static String formatUnits (String value)
    {
        if (value == null) return null;

        String returnVal = null;
        int inputVal = 0;
        boolean success = false;
        try {
            inputVal = Integer.parseInt(value);
            success = true;
        }
        catch (NumberFormatException nfe) {
            System.out.println ("StringUtils.formatUnits() -> Invalid value \"" + value + "\", returning null");
        }

        if (success == false) {
            return null;
        }

        DecimalFormat myFormatter = new DecimalFormat("###,###");
        return myFormatter.format(inputVal);
    }


	// BR, On June 04, 2004
	public static int formatUnitsToInt( String units )
    {
    	String returnString = "";
       	String NumberDelimiters = ",";

    	for (int i=0; i<units.length(); i++)
    	{
			char c = units.charAt(i);
           	if(NumberDelimiters.indexOf(c) == -1)
           	{
           		returnString += c;
           	}
    	}

    	return Integer.parseInt( returnString );
   	}



   public static float formatToFloat(String amount)
   {
       String returnString = "";
       String NumberDelimiters = "$,";
    for (int i=0; i<amount.length(); i++)
    {
           // Check that current character isn't Number Delimiters
           char c = amount.charAt(i);
           if (NumberDelimiters.indexOf(c) == -1)
                returnString += c;
    }

    return Float.parseFloat(returnString);
   }

   // Begin : Added by Basha (09/19/2003)  Inorder to handle quoted string values
   public static String formatToHandleQuote(String oldString)
   {
        StringBuffer newString = new StringBuffer();
        int fromindex = 0;

        //System.out.println("Actual String           : "+oldString);

        while(oldString.indexOf("'", fromindex) != -1)
        {
            newString.append( oldString.substring ( fromindex , ( oldString.indexOf("'", fromindex) ) + 1) ).append("'");
            fromindex = oldString.indexOf("'", fromindex) + 1;
        }

        newString.append(oldString.substring(fromindex , oldString.length()));

        //System.out.println("After Conversion String : "+newString.toString());

        return newString.toString();
   }
   // End : Added by Basha (09/19/2003)


    /**
     * checks whether the String passed is null or not
     * @ param str String to be checked.
     * @ return true if the String is null, false otherwise
     */
    public static boolean isNull(String str)
    {
        return str == null;
    }

    /**
     * checks whether the String passed is empty or not
     * @ param str String to be checked.
     * @ return true if the String is empty, false otherwise
     */
    public static boolean isEmpty(String str)
    {
        return str.trim().length() == 0;
    }

   /**
    * checks whether the String passed is either null or empty
    * @ param str String to be checked.
    * @ return true if the String is null or empty, false otherwise
    */
    public static boolean isNullOrEmpty(String str)
    {
        return isNull(str) || isEmpty(str);
    }

    public static String replaceCharAt(String s, int pos, char c)
	{
		return s.substring(0,pos) + c + s.substring(pos+1);
	}

    public static char getNextCharFromArray(char ch, char[] alphabetArray )
	{
		char nextch='0';

		for (int i = 0; i < alphabetArray.length; i++)
		{
			if (alphabetArray[i]==ch )
			{
				if ( (i+1) >=alphabetArray.length )
				{
					nextch = alphabetArray[0];
				}
				else
				{
					nextch = alphabetArray[i+1];
				}

			}
		}

       return nextch;
    }

    public static boolean isLastCharInArray(char ch, char[] alphabetArray )
	{
		return alphabetArray[alphabetArray.length-1]==ch ? true : false;
    }
    public static String escapeSpecialString(String s){
            int length = s.length();

            StringBuffer sb = new StringBuffer(length);
            for (int i=0; i<length; i++){
                char c = s.charAt(i);
                int cint = 0xffff & c;
                if (cint < 32){
                    switch(c){
                        case '\r':{
                            sb.append("\\r");
                            break; }
                        case '\n':{
                            sb.append("\\n");
                            break; }
                        case '\t':{
                            sb.append("\\t");
                            break; }
                        case '\f':{
                            sb.append("\\f");
                            break; }
                        default: {
                            // Remove this character
                        }
                    }
                } else {
                    switch(c){
                        case '\"':{
                            sb.append("\\\"");
                        } break;
                        case '\'':{
                            sb.append("\\\'");
                        } break;
                        default: {
                            sb.append(c);
                        }
                    }
                }
            }
            return sb.toString();
        }

    public static String escapeHTML(String s){
            int length = s.length();
            StringBuffer sb = new StringBuffer(length);
            for (int i=0; i<length; i++){

                char c = s.charAt(i);
                int cint = 0xffff & c;
                if (cint < 32){
                   switch(c){
                        case '\r':
                        case '\n':
                        case '\t':
                        case '\f':{
                            sb.append(c);
                        } break;
                        default: {
                            // Remove this character
                        }
                    }
                } else {
                    switch(c){
                        case '\"':{
                            sb.append("&quot;");
                        } break;
                        case '\'':{
                            sb.append("&#39;");
                        } break;
                        case '&':{
                            sb.append("&amp;");
                        } break;
                        case '<':{
                            sb.append("&lt;");
                        } break;
                        case '>':{
                            sb.append("&gt;");
                        } break;
                        default: {
                            sb.append(c);
                        }
                    }
                }
            }
            return sb.toString();
        }
    //to encode all special characters
    public static String encodeAllSpecialCharacters(String value)
    {
          String encodedValue = null;
        try{
                encodedValue = URLEncoder.encode(value,"UTF-8");
        }catch(UnsupportedEncodingException e){e.printStackTrace();}

              return encodedValue;
    }

    public static String getformat(String value)
    {
        if(value != null)
        {
        if( Integer.parseInt(value) > 999 )
            {
               value = "0"+value;
            }
            else if( Integer.parseInt(value) > 99 )
            {
               value = "00"+value;
            }
             else if( Integer.parseInt(value) > 9 )
            {
               value = "000"+value;
            }

            else if( Integer.parseInt(value) <= 9 )
            {
               value = "0000"+value;
            }
        }
       return  value;
    }

    // Added by Basha (06/16/2004)
    public static String getUSNumberFormat(int number){

        NumberFormat nf = NumberFormat.getIntegerInstance(Locale.US);

        return nf.format(number);
    }

    /**
     * This method returns if the given string is a numeric value
     *
     * @param str
     * @return
     */
    public static boolean isNumeric( String str )
	{
    	boolean isNumeric = true;
    	try
		{
    		Integer.parseInt( str );
    	}
    	catch( NumberFormatException ne )
		{
    		isNumeric = false;
    	}
    	return isNumeric;
    }

    public static double formatToDouble(String amount)
    {

        String returnString = "";

        for (int i = 0; i < amount.length(); i++)
        {
            //adding only those characters which are decimals or is a period(.)
            char c = amount.charAt(i);
            if( ( Character.isDigit( c ) ) || ( c == '.' ) || ( c == '-' ) )
            {
                returnString += c;
            }
        }

        return Double.parseDouble( returnString );
    }


    //this method is to eliminate the duplicate mail ids from a string of mails which r seperated by commas
    public static String removeDuplicateEmailIds(String emails) throws ScalarException
    {
       StringBuffer finalMails = new StringBuffer();
       try
       {
            if(emails == null) {
                return null;
            }

            String []emailArray =  toStringArray(emails, ",");  //convert the String to array of mails
            int length = emailArray.length ;
            ArrayList finalList = new ArrayList();

            for(int i=0; i<length; i++)
            {
                boolean flag = true;
                if(finalList.size() == 0){
                    finalList.add( emailArray[0] );
                }
                else{
                    for(int j=0; j<finalList.size() ; j++)
                    {
                        if( emailArray[i] != null && emailArray[i].trim().equals((String)finalList.get(j)) )
                        {
                           flag = false;
                           break;
                        }
                    }
                    if(flag && emailArray[i] != null){
                        finalList.add(emailArray[i].trim()) ;
                    }
                }
           }
           if(finalList != null){
               for(int i=0; i<finalList.size() ; i++)
               {
                   if(finalMails.length() == 0){
                        finalMails.append((String)finalList.get(i)) ;
                   }
                   else{
                        finalMails.append(", ").append((String)finalList.get(i)) ;
                   }
               }
           }
       }
       catch(ScalarException se)
       {
            throw new ScalarException ("Exception while removing Duplicate Email Ids Emails", se);
       }

       return finalMails.toString() ;
    }

    public static String convertLowerCaseToUpperCase( String mixedCaseString )
    {
    	char[] tempCapitalChar = null;
        if( mixedCaseString != null && mixedCaseString.length() > 0 )
        {
            tempCapitalChar = new char[ mixedCaseString.length() ];
            mixedCaseString.getChars( 0, mixedCaseString.length(), tempCapitalChar, 0 );

            for ( int i = 0; i < tempCapitalChar.length; i++ )
        	{
        		if( Character.isLowerCase( tempCapitalChar[i] ) )
        		{
        			tempCapitalChar[i] = Character.toUpperCase( tempCapitalChar[ i ] );
        		}
        	}
        }
        else
        {
        	return mixedCaseString;
        }

        return new String( tempCapitalChar );
    }

    public static void main (String[] args) {
        /*System.out.println ("13.2 = " + formatAmount (13.2f, null));
        System.out.println ("13 = " + formatAmount (13f, null));
        System.out.println ("13.2455 = " + formatAmount (13.2455f, null));
        System.out.println ("13.2415 = " + formatAmount (13.2415f, null));
        System.out.println ("13.15 = " + formatAmount (13.15f, null));
        System.out.println (format("20030105", "yyyyMMdd"));          */



        System.out.println( "Next number for SKU1233008 = " + incrementNumberPart( "SKU1233008" ) );
    }


    public static String formatNumber( float value, String pattern )
    {
        if( isNullOrEmpty( pattern ) )
        {
            pattern = "###,###,###,###.##";
        }
         DecimalFormat myFormatter = new DecimalFormat(pattern);

        String formattedValue = myFormatter.format(value);

        int index = formattedValue.indexOf('.');
        if (index == -1)
        {
            formattedValue += ".00";
        }
        else
        {
            String substring = formattedValue.substring (index+1, formattedValue.length());
            if (substring.length() == 1)
            {
                formattedValue += "0";
            }
        }
        return formattedValue;
    }

    public static String trimLeadingChar(String str, char removeChar)
    {
       if(isNullOrEmpty(str) )
           return str;
                StringBuffer buf;
       for(buf = new StringBuffer(str); buf.length() > 0 && removeChar == buf.charAt(0); buf.deleteCharAt(0));
        return buf.toString();
    }

    public static int searchArray( String[] strArray, String searchValue)
    {
        for (int i = 0; i < strArray.length; i++)
        {
            if (strArray[i].equals(searchValue))
            {
                return i;
            }
        }
        return -1;
    }

    public static boolean hasLength(String str)
    {
        return (str != null && str.trim().length() > 0);
    }
    public static boolean hasText(String str)
    {
		if (!hasLength(str)) {
			return false;
		}
		int strLen = str.length();
		for (int i = 0; i < strLen; i++) {
			if (!Character.isWhitespace(str.charAt(i))) {
				return true;
			}
		}
		return false;
	}
    public static double Round(double value, String format )
    {
        if (isNullOrEmpty( format) )
         format = "#############.0";

        DecimalFormat df2 = new DecimalFormat( format );

        return new Double(df2.format(value)).doubleValue();
    }
    public static double Round(double Rval, int Rpl)
    {
          double p = (double)Math.pow(10,Rpl);
          Rval = Rval * p;
          double tmp = Math.round(Rval);
          return (double)tmp/p;
    }
    public static String encode ( String name )
    {
        String encodedName = "";

        int nameLength = ( name != null ) ? name.length() : 0;
        char ch;
        for ( int i = 0; i < nameLength; i++ )
        {
            ch = name.charAt(i);
            if ( ( ch >= 'a' && ch <= 'z' ) || (ch >= 'A' && ch <= 'Z' ) || ( ch >= '0' && ch <= '9' )
                    || ch == '-' || ch == '_' || ch == '.' ) //not encoded
            {
                encodedName = encodedName + ch;
            }
            else
            {
                String hexValue = Integer.toHexString( ch ).toUpperCase();
                encodedName = encodedName + "%" + hexValue;
            }
        }
        return encodedName;
    }

    public static int getNexInttRandom() {
        return random.nextInt();
    }
}